import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/21 10:04
 * @description 直接计数，逆序减最大值
 */
public class Solution2 {
    public static void main(String[] args) {
        Solution2 solution2 = new Solution2();
        int[] p = {10000};
        solution2.minStoneSum(p, 10000);
    }
    public int minStoneSum(int[] piles, int k) {
        int[] cnt = new int[10001];
        int sum = 0;
        for (int p: piles) {
            cnt[p]++;
            sum += p;
        }
        for (int i = 10000; k > 0;) {
            if (cnt[i] > 0) {
                sum -= i / 2;
                cnt[i]--;
                cnt[(i+1) / 2]++;
                k--;
            }else {
                i--;
            }
        }
        return sum;
    }
}
